SlidingWindowCircuitBreaker

JS/TS-friendly facade over com.sorinirmies.arrow.resiliencekit.SlidingWindowCircuitBreaker.

import { SlidingWindowCircuitBreaker } from "arrow-resilience-kit";

const cb = await SlidingWindowCircuitBreaker.create({ slidingWindowSize: 20, failureRateThreshold: 0.5 });
const result = await cb.execute(() => externalService.call());

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard

Current state: "Closed", "Open", or "HalfOpen".

Link copied to clipboard
fun <T> execute(block: () -> Promise<T>): Promise<T>

Executes block through the circuit breaker. Rejects with an error if the circuit is open.

Link copied to clipboard
fun <T> executeOrFallback(fallback: () -> Promise<T>, block: () -> Promise<T>): Promise<T>

Executes block, falling back to fallback if the circuit is open.

Link copied to clipboard
fun onStateChange(listener: (oldState: String, newState: String) -> Unit)

Registers listener to be called (with the old and new state names) on every state change.

Link copied to clipboard

Manually resets the circuit breaker to closed state and clears its window.

Link copied to clipboard

Current window statistics snapshot.